CP		= cp
RM		= rm
MD		= mkdir
CC		= gcc
LN		= ln -s

CFLAGS		= -W -Wall -fPIC
LIBFLAGS	= -shared
LNKFLAGS	= -lpthread -lncurses

LIBPATH		= lib
OBJPATH		= obj
SRCPATH		= src

VERSION		= 1

DESTDIR		= /usr
DESTLIB		= $(DESTDIR)/lib
DESTINC		= $(DESTDIR)/include/CSLP-D

LIBNAME		= libcslp-d.so.$(VERSION)
LIBLNKNAME	= libcslp-d.so

SOURCES		= $(SRCPATH)/Clock.c $(SRCPATH)/Colors.c $(SRCPATH)/Cursor.c $(SRCPATH)/Error.c $(SRCPATH)/Init.c $(SRCPATH)/Input.c $(SRCPATH)/Mutex.c $(SRCPATH)/Network.c $(SRCPATH)/System.c $(SRCPATH)/TCP.c $(SRCPATH)/UDP.c
HEADERS		= $(SOURCES:.c=.h) $(SRCPATH)/CSLP.h $(SRCPATH)/dll.h
OBJECTS		= $(SOURCES:.c=.o)

EXEC		= $(LIBPATH)/$(LIBNAME)

###########################################################
#	Début des instructions
###########################################################

all			: $(EXEC)
#linkage des fichiers compilés
$(EXEC)			: $(OBJECTS) $(LIBPATH)
	$(CC) $(LIBFLAGS) $(OBJECTS) -o $@ $(LNKFLAGS)
#création du dossier de destination de la librairie
$(LIBPATH)		:
	$(MD) $@
#compilation des fichier
$(SRCPATH)/%.o		: $(SRCPATH)/%.c
	$(CC) -c $< -o $@ $(CFLAGS)

#instructions de nettoyage

.PHONY			: clean mrproper

clean			:
	$(RM) -f $(OBJECTS)

mrproper		: clean
	$(RM) -f $(EXEC)

###########################################################
#	instructions d'installation
###########################################################
install			: all uninstall $(DESTINC) $(HEADERS)
	$(CP) $(EXEC) $(DESTLIB)
	$(CP) $(HEADERS) $(DESTINC)
	$(LN) $(DESTLIB)/$(LIBNAME) $(DESTLIB)/$(LIBLNKNAME)

$(DESTINC)		:
	$(MD) $(DESTINC)

uninstall		:
	$(RM) -f $(DESTLIB)/$(LIBNAME) $(DESTLIB)/$(LIBLNKNAME)
	$(RM) -f $(DESTINC)/*.h
